#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <stack>

using namespace std;

#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)

#define INF (1<<29)

int N;
vector <int> graph[510];
int dist[510][510][2],prev[510][510][2];
queue <int> q;
vector <int> apath,bpath;

int main(void){
    int M,i,j,k,a,b;
    
    scanf("%d%d",&N,&M);
    REP(i,M){
        scanf("%d%d",&a,&b); a--; b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    
    REP(i,N) REP(j,N) REP(k,2) dist[i][j][k] = INF;
    dist[0][N-1][0] = 0; q.push(0); q.push(N-1); q.push(0);
    
    while(!q.empty()){
        a = q.front(); q.pop(); b = q.front(); q.pop(); int type = q.front(); q.pop();
        
        if(type == 0){ // a moves
            REP(i,graph[a].size()){
                int c = graph[a][i];
                if(dist[c][b][1] == INF){
                    dist[c][b][1] = dist[a][b][0] + 1;
                    prev[c][b][1] = a;
                    q.push(c); q.push(b); q.push(1);
                }
            }
        } else { // b moves
            REP(i,graph[b].size()){
                int c = graph[b][i];
                if(c == a) continue;
                if(dist[a][c][0] == INF){
                    dist[a][c][0] = dist[a][b][1] + 1;
                    prev[a][c][0] = b;
                    q.push(a); q.push(c); q.push(0);
                }
            }
        }
    }
    
    int ans = dist[N-1][0][0];
    if(ans == INF){
        cout << -1 << endl;
        return 0;
    }
    
    cout << ans / 2 << endl;
    
    a = N-1; b = 0;
    apath.push_back(a); bpath.push_back(b);
    REP(i,ans/2){
        b = prev[a][b][0]; bpath.push_back(b);
        a = prev[a][b][1]; apath.push_back(a);
    }
    reverse(apath.begin(),apath.end());
    reverse(bpath.begin(),bpath.end());
    
    REP(i,apath.size()){
        printf("%d",apath[i]+1);
        if(i == apath.size() - 1) printf("\n"); else printf(" ");
    }
    
    REP(i,bpath.size()){
        printf("%d",bpath[i]+1);
        if(i == bpath.size() - 1) printf("\n"); else printf(" ");
    }
    
    return 0;
}
